/**
 * @(#)DbSupport.java, 2013年10月28日. Copyright 2012 Yodao, Inc. All rights
 *                     reserved. YODAO PROPRIETARY/CONFIDENTIAL. Use is subject
 *                     to license terms.
 */
package com.scitc.pleasurevideo.datasql;

import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;

import com.scitc.pleasurevideo.x5webview.MyApplication;


/**
 * @author contradiction 写个Db操作的超类
 */
public class DbSupport {

    public static final String DB_PATH = "/security/db/data.db";

    public static final String SYSTEM_DATABASE_NAME = "wordbook.db";

    public static final int SYSTEM_DATABASE_VERSION = 1;

    private String dbPath;

    private DBConnection dbConnection;

    public DbSupport() {
        dbPath = Environment.getExternalStorageDirectory() + DB_PATH;
        dbConnection = new DBConnection(MyApplication.getInstance());
    }

    public DbContext getSystemDbContext() {
        return new DbContext(dbConnection.getWritableDatabase());
    }

    public DbContext getDefaultDbContext() {
        return new DbContext(this.getDefaultDB());
    }

    public DbContext getDbContext(String path) {
        return new DbContext(this.getDB(path));
    }

    public SQLiteDatabase getDefaultDB() {
        return getDB(dbPath);
    }

    public SQLiteDatabase getDB(String path) {
        return SQLiteDatabase.openDatabase(path, null,
                SQLiteDatabase.OPEN_READWRITE);
    }

    public String getDbPath() {
        return dbPath;
    }

    public void setDbPath(String dbPath) {
        this.dbPath = dbPath;
    }
}
